﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Main.Master" AutoEventWireup="true"
    CodeBehind="List.aspx.cs" Inherits="APMS.WebSite.Views.Message.List" %>

<%@ Import Namespace="APMS.WebSite.Common" %>    
<%@ Import Namespace="APMS.WebSite.Models.DataStore" %>
<%@ Import Namespace="APMS.WebSite.Models.ViewData.UserControls" %>

<asp:Content ID="ScriptContent" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="PageTitleContent" ContentPlaceHolderID="PageTitleHolder" runat="server">
    <h2 class="nodesc"><%= Html.Encode(((Project)ViewData[ProjectBaseController.CURRENT_PROJECT]).ProjectName)%></h2>
    <h3>All Messages</h3>
</asp:Content>
<asp:Content ID="NavigationMenuContent" ContentPlaceHolderID="NavigationMenuHolder" runat="server">
    <%=Html.RenderUserControl("~/Views/Shared/UserControls/MainNav.ascx", ViewData[BaseController.MAIN_NAV])%>
</asp:Content>
<asp:Content ID="CommandLinkContent" ContentPlaceHolderID="CommandLinkHolder" runat="server">
</asp:Content>
<asp:Content ID="SidebarContent" ContentPlaceHolderID="SidebarHolder" runat="server">
    <div class="widget">
        <h3 class="widgetTitle">Actions</h3>
        <div class="widgetContent">
            <%=Html.Image(AppHelper.GetThemePath() + "images/add.png", new { alt="New", title="New Message", style="vertical-align:top" }) %>
            <%=Html.ActionLink<MessageController>(x => x.Create(((Project)ViewData[ProjectBaseController.CURRENT_PROJECT]).ProjectID), "Create a new message")%>
        </div>
    </div>
</asp:Content>
<asp:Content ID="MainContent" ContentPlaceHolderID="ContentHolder" runat="server">
    <div class="contentWrap">
    <%
        List<Message> allMessages = ViewData[MessageController.ALL_MESSAGES] as List<Message>;
        if ((allMessages != null) && (allMessages.Count > 0))
        {
            StringBuilder msgBuilder = null;
            Project currentProject = null;
            foreach (Message message in allMessages)
            {
                msgBuilder = new StringBuilder();
                currentProject = (Project)ViewData[ProjectBaseController.CURRENT_PROJECT];
                string viewMessageLink = "/InProject/" + currentProject.ProjectID + "/Message/View/" + message.MessageID;
                string editMessageLink = "/InProject/" + currentProject.ProjectID + "/Message/Update/" + message.MessageID;
                
                // Date of post
                msgBuilder.AppendFormat("<h2 class=\"date\"><span>{0}</span></h2>", 
                    message.ModifyDate.ToString(AppHelper.DateTimeFormat));
                // Message Content
                msgBuilder.AppendLine("<div class=\"message\">");
                msgBuilder.AppendFormat("<h1 class=\"title\"><a href=\"{0}\">{1}</a></h1>", 
                    viewMessageLink,
                    message.MessageTopic);
                msgBuilder.AppendFormat("<div class=\"content\">{0}</div>", message.MessageDetail);
                msgBuilder.AppendFormat("<div class=\"meta\"><img alt=\"Meta\" title=\"Message Meta-Information\" src=\"{2}\" /><span> Posted by {0} on {1} | <a href=\"{3}\">Edit</a> | <a href=\"{4}\">1 comment(s)</a></span></div>",
                    message.UserName,
                    message.ModifyDate.ToString(AppHelper.DateTimeFullFormat),
                    AppHelper.GetThemePath() + "images/messages/anchor.png",
                    editMessageLink, 
                    viewMessageLink);
                msgBuilder.AppendLine("</div>");

                Response.Flush();
                Response.Write(msgBuilder.ToString());
            }
        }
    %>
    </div>
</asp:Content>
